package com.lingx.web.api.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.lingx.model.IModel;
import com.lingx.service.ModelService;
import com.lingx.web.api.IApi;
@Component
public class Api9010 extends AbstractDevApi implements IApi{
	@Resource
	private ModelService modelService;
	@Override
	public int getApiCode() {
		return 9010;
	}
	@Override
	public String getApiName() {
		return "动态添加模型";
	}
	@Override
	public Map<String, Object> api(Map<String, Object> param) {
		Map<String,Object> ret=IApi.getRetMap(1, "SUCCESS");
		String code=param.get("code").toString();
		String id=param.get("id").toString();
		String type=param.get("type").toString();
		IModel model=null;
		if("field".equals(type)) {
			model=this.modelService.addField(code, id);
		}else if("method".equals(type)) {
			model=this.modelService.addMethod(code, id);
		}
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("id",model.getId() );
		map.put("modelType",model.getModelType() );
		map.put("label",model.getName()+" ["+model.getCode()+"]" );
		map.put("icon",model.getIconCls());
		map.put("leaf", model.getLeaf());
		ret.put("data", map);
		//this.modelService.addValidator(code, id);
		return ret;
	}

}
